/**
 * 
 */
package com.cms.action;

import java.util.List;

import org.apache.log4j.Logger;

import com.action.DefaultAction;
import com.cms.model.AppInfo;
import com.cms.model.AppPointEntry;
import com.cms.service.AppInfoService;
import com.cms.service.AppInfoServiceImpl;
import com.cms.service.AppPointOfBillingService;
import com.cms.service.AppPointOfBillingServiceImpl;


public class AppPointEntryAction extends DefaultAction {

	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;

	private Logger logger;
	
	public AppPointEntryAction()
	{
		logger = Logger.getLogger(this.getClass());
	}
	
	public String execute()
	{
		return SUCCESS;
	}

	private List<AppPointEntry> list;
	private AppPointEntry       model;
	private String        type;
	AppInfo appinfo;
	AppPointOfBillingService service = new AppPointOfBillingServiceImpl();
	AppInfoService appservice = new AppInfoServiceImpl();
	String msg;
	
	public String list()
	{
		list = service.getPointEntryByModel(model);
		appinfo = appservice.getAppInfoByAppNumber(model.getAppnumber());
		return SUCCESS;
	}
	
	public String show()
	{
		if (model.getId() >= 0)
		{
			model = service.getPointEntryByModel(model).get(0);
			type = "update";
		}		
		else
		{
			model.setId(-1);
			type = "insert";
		}

		return SUCCESS;
	}
	
	
	public String save()
	{
		
		boolean fl = service.savePointEntry(type, model);
		
		if(type.equals("insert"))
		{
			if(fl)
				msg = "计费点入口管理：添加成功";
			else
				msg = "计费点入口管理：添加失败！请重新添加！";
		}
		else if(type.equals("update"))
		{
			if(fl)
				msg = "计费点入口管理：更新成功！";
			else
				msg = "计费点入口管理：更新失败！请重新更新！";
			type = "upd";
		}
		else if(type.equals("delete"))
		{
			if(fl)
				msg = "计费点入口管理：删除成功！";
			else
				msg = "计费点入口管理：删除失败！请重新删除！";
		}
		return SUCCESS;
	}

	public List<AppPointEntry> getList() {
		return list;
	}

	public void setList(List<AppPointEntry> list) {
		this.list = list;
	}

	public AppPointEntry getModel() {
		return model;
	}

	public void setModel(AppPointEntry model) {
		this.model = model;
	}

	public String getType() {
		return type;
	}

	public void setType(String type) {
		this.type = type;
	}

	public AppInfo getAppinfo() {
		return appinfo;
	}

	public void setAppinfo(AppInfo appinfo) {
		this.appinfo = appinfo;
	}

	public String getMsg() {
		return msg;
	}

	public void setMsg(String msg) {
		this.msg = msg;
	}
	
}
